package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author xiongkunYang
 * @since 2025/05/26 18:30
 */
@Tag(name = "分类品牌")
@RestController
@RequestMapping("/categoryBrand")
@RequiredArgsConstructor
public class CategoryBrandController extends BaseController {

    private final ICategoryBrandService categoryBrandService;

    @Operation(summary = "查询分类品牌列表")
    @GetMapping("list")
    public TableDataInfo list() {
        super.startPage();
        List<CategoryBrand> list = this.categoryBrandService.categoryBrandList();
        return super.getDataTable(list);
    }

    @Operation(summary = "新增分类品牌")
    @Parameters({
            @Parameter(name = "categoryBrand", description = "分类品牌信息")
    })
    @Log(title = "分类品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return super.toAjax(this.categoryBrandService.saveCategoryBrand(categoryBrand));
    }

    @Operation(summary = "删除分类品牌")
    @Parameters({
            @Parameter(name = "ids", description = "分类品牌id列表", example = "[1,2]")
    })
    @Log(title = "分类品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return super.toAjax(this.categoryBrandService.removeBatchByIds(ids));
    }

    @Operation(summary = "根据分类id获取品牌列表")
    @Parameters({
            @Parameter(name = "categoryId", description = "分类id")
    })
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult brandListByCategoryId(@PathVariable Long categoryId) {
        return super.success(this.categoryBrandService.brandListByCategoryId(categoryId));
    }
}
